package com.fare.taluo.core.domain.config.line;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Table;

import com.dayatang.domain.Entity;
import com.dayatang.domain.InstanceFactory;
import com.dayatang.domain.QuerySettings;
import com.fare.taluo.base.ddd.domain.baseentity.BaseEntity2;
import com.fare.taluo.core.domain.config.city.PortEntity;

@javax.persistence.Entity
@Table(name = "FDC_FLIGHTINFO")
@SuppressWarnings("serial")
public class FlightInfoEntity extends BaseEntity2<FlightInfoEntity> implements Entity{
	
//	@Id
//	@Column(name="ID", length=32)
//	@GeneratedValue(generator="system-uuid")
//	@org.hibernate.annotations.GenericGenerator(name="system-uuid", strategy="uuid")
//	private String id;
	
	@Column(name = "FROMCITY")
	private String fromCity;
	@Column(name = "TOCITY")
	private String toCity;
	@Column(name = "FROMCITYNAME")
	private String fromCityName;
	@Column(name = "TOCITYNAME")
	private String toCityName;
	@Column(name = "FLIGHTNO")
	private String flightNo;
//	@Column(name="carrier_key")
//	private String carrierKey;
	
	@Column(name = "AREA_NAME")
	private String areaName;
	@Column(name = "AREA_CODE")
	private String areaCode;

	@Column(name = "COMPANY_CODE")
	private String companyCode;
	@Column(name = "COMPANY_NAME")
	private String companyName;
	@Column(name="flight_start_time")//起飞时间
	private String flightStartTime;
	@Column(name="flight_end_time")
	private String flightEndTime;
	@Column(name="frequence")
	private String frequence;//班次
	@Column(name="entry_time")
	private Date entryTime;//入库时间
	@Column(name="effect_start_time")
	private String effectStartTime;//有效开始时间
	@Column(name="effect_end_time")
	private String effectEndTime;//有效结束时间
	@Column(name="transfercity")
	private String transferCity;//中转机场代码
	@Column(name="transfercityname")
	private String transferCityName;//中转机场代码
	@Column(name="transfer_start_time")
	private String transferStartTime;//航段二飞机起飞时间
	@Column(name="transfer_end_time")
	private String transferEndTime;//航段一起飞时间
	@Column(name="first_share_flight")
	private String firstShareFlight;//航程一的航班是否共享航班
	@Column(name="second_share_flight")
	private String secondShareFlight;//航程二的航班是否共享航班
	@Column(name="transfer_flightno")
	private String transgerFlightNo;//航程二航班号
	@Column(name="first_class")
	private String firstClass;//航程一舱位
	@Column(name="second_class")
	private String secondClass;//航程二舱位
	@Column(name="first_flight_type")
	private String firstFlightType;//航程一机型
	@Column(name="second_flight_type")
	private String secondFlightType;//航程二机型
	@Column(name="stopcity")
	private String stopCity;
	@Column(name="flight_date")
	private String flightDate;
	
	public String getFlightStartTime() {
		return flightStartTime;
	}
	public void setFlightStartTime(String flightStartTime) {
		this.flightStartTime = flightStartTime;
	}
	public String getAreaName() {
		return areaName;
	}
	public void setAreaName(String areaName) {
		this.areaName = areaName;
	}
	public String getAreaCode() {
		return areaCode;
	}
	public void setAreaCode(String areaCode) {
		this.areaCode = areaCode;
	}
	public String getCompanyCode() {
		return companyCode;
	}
	public void setCompanyCode(String companyCode) {
		this.companyCode = companyCode;
	}
	public String getCompanyName() {
		return companyName;
	}
	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}
	
//	public String getId() {
//		return id;
//	}
//	public void setId(String id) {
//		this.id = id;
//	}
	public String getFromCity() {
		return fromCity;
	}
	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}
	public String getToCity() {
		return toCity;
	}
	public void setToCity(String toCity) {
		this.toCity = toCity;
	}
	public String getFromCityName() {
		return fromCityName;
	}
	public void setFromCityName(String fromCityName) {
		this.fromCityName = fromCityName;
	}
	public String getToCityName() {
		return toCityName;
	}
	public void setToCityName(String toCityName) {
		this.toCityName = toCityName;
	}
	public String getFlightNo() {
		return flightNo;
	}
	public void setFlightNo(String flightNo) {
		this.flightNo = flightNo;
	}
    

	public String getFrequence() {
		return frequence;
	}
	public void setFrequence(String frequence) {
		this.frequence = frequence;
	}
    
    
	public String getFlightEndTime() {
		return flightEndTime;
	}
	public void setFlightEndTime(String flightEndTime) {
		this.flightEndTime = flightEndTime;
	}
    

    

	public Date getEntryTime() {
		return entryTime;
	}
	public void setEntryTime(Date entryTime) {
		this.entryTime = entryTime;
	}
	public String getEffectStartTime() {
		return effectStartTime;
	}
	public void setEffectStartTime(String effectStartTime) {
		this.effectStartTime = effectStartTime;
	}
	public String getEffectEndTime() {
		return effectEndTime;
	}
	public void setEffectEndTime(String effectEndTime) {
		this.effectEndTime = effectEndTime;
	}
	public String getTransferStartTime() {
		return transferStartTime;
	}
	public void setTransferStartTime(String transferStartTime) {
		this.transferStartTime = transferStartTime;
	}
	public String getTransferEndTime() {
		return transferEndTime;
	}
	public void setTransferEndTime(String transferEndTime) {
		this.transferEndTime = transferEndTime;
	}
	
	public String getTransferCity() {
		return transferCity;
	}
	public void setTransferCity(String transferCity) {
		this.transferCity = transferCity;
	}
	public String getTransferCityName() {
		return transferCityName;
	}
	public void setTransferCityName(String transferCityName) {
		this.transferCityName = transferCityName;
	}
	public String getFirstShareFlight() {
		return firstShareFlight;
	}
	public void setFirstShareFlight(String firstShareFlight) {
		this.firstShareFlight = firstShareFlight;
	}
	public String getSecondShareFlight() {
		return secondShareFlight;
	}
	public void setSecondShareFlight(String secondShareFlight) {
		this.secondShareFlight = secondShareFlight;
	}
	public String getTransgerFlightNo() {
		return transgerFlightNo;
	}
	public void setTransgerFlightNo(String transgerFlightNo) {
		this.transgerFlightNo = transgerFlightNo;
	}
	public String getFirstClass() {
		return firstClass;
	}
	public void setFirstClass(String firstClass) {
		this.firstClass = firstClass;
	}
	public String getSecondClass() {
		return secondClass;
	}
	public void setSecondClass(String secondClass) {
		this.secondClass = secondClass;
	}
	public String getFirstFlightType() {
		return firstFlightType;
	}
	public void setFirstFlightType(String firstFlightType) {
		this.firstFlightType = firstFlightType;
	}
	public String getSecondFlightType() {
		return secondFlightType;
	}
	public void setSecondFlightType(String secondFlightType) {
		this.secondFlightType = secondFlightType;
	}
    
    


	public String getFlightDate() {
		return flightDate;
	}
	public void setFlightDate(String flightDate) {
		this.flightDate = flightDate;
	}
	public String getStopCity() {
		return stopCity;
	}
	public void setStopCity(String stopCity) {
		this.stopCity = stopCity;
	}




	//private static FlightInfoEntityRepository flightRepository = InstanceFactory.getInstance(FlightInfoEntityRepository.class);
	
	protected FlightInfoEntityRepository getFlightInfoEntityRepository(){
		return InstanceFactory.getInstance(FlightInfoEntityRepository.class);
	}
	
	public List<FlightInfoEntity> findByLine(String fromCityCode,String toCityCode){
		return getFlightInfoEntityRepository().findByLine(fromCityCode, toCityCode);
	}
	public List<FlightInfoEntity> findByLine(String fromCityCode,String toCityCode,String air_key){
		return getFlightInfoEntityRepository().findByLine(fromCityCode, toCityCode,air_key);
	}
	public List<FlightInfoEntity> findByLine(List<PortEntity> fromCityCode,List<PortEntity> toCityCode,String air_key){
		return getFlightInfoEntityRepository().findByLine(fromCityCode, toCityCode,air_key);
	}
	
	
	public List<FlightInfoEntity> findByLineAndDate(String fromCityCode,String toCityCode,String air_key){
		return getFlightInfoEntityRepository().findByLineAndDate(fromCityCode, toCityCode,air_key);
	}
	
	public List<FlightInfoEntity> findByLineCodeNotIn(String fromCityCode,String toCityCode,String companyCodeNoin){
		return getFlightInfoEntityRepository().findByLineCodeNotIn(fromCityCode, toCityCode,companyCodeNoin);
	}
	public List<FlightInfoEntity> findLineByCodes(String fromCityCode, String toCityCode, String carrier_key) {
		return getFlightInfoEntityRepository().findLineByCodes(fromCityCode,toCityCode,carrier_key);
	}

	//因为OccupRateEntity需要，所以增加了此方法
	public List<FlightInfoEntity> findByFlightNo(String flightNo){
		return getFlightInfoEntityRepository().findByFlightNo(flightNo);
	}
    
	public void save(FlightInfoEntity entity){
		getFlightInfoEntityRepository().save(entity);
	}
	
	public void tranSave(FlightInfoEntity entity){
		getFlightInfoEntityRepository().tranSave(entity);
	}
	
	public List<FlightInfoEntity> findByConditions(String company,String fromCityName,String toCityName,String flightNo,Date entryTime){
		return getFlightInfoEntityRepository().findByConditions(company,fromCityName,toCityName,flightNo,entryTime);
	}
	

	@Override
	public boolean isNew() {
		return getId() == null ;
	}

	@Override
	public boolean existed() {
		if (isNew()) {
			return false;
		}
		return getRepository().exists(getClass(), getId());
	}

	@Override
	public boolean notExisted() {
		return ! existed();
	}
	
	@Override
	public boolean existed(String propertyName, Object propertyValue) {
		List<?> entities = getRepository().find(QuerySettings.create(getClass()).eq(propertyName, propertyValue)); 
		return !(entities.isEmpty());
	}
	
	
}
